<!DOCTYPE html>
<html lang="en">

<head>
    <#include "/jh/admin/components/meta.html" />
    <title>上课历史 ${metaTitleSuffix!}</title>
    <#include "/jh/admin/components/stylesheets.html" />
</head>

<body>
    <div id="app">
        <el-container>
            <#assign menuIndex="2-1" />
            <#include "/jh/admin/components/menu.html" />
            <el-container>
                <#include "/jh/admin/components/header.html" />
                <el-main>
                    <template>
                        <el-row>
                            <el-col :span="12" style="display: flex; align-items: center;">
                                <div class="title theme-color1">上课历史</div>
                                <div class="datepicker">
                                    <el-date-picker v-model="date" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" @change="onDateChange" unlink-panels="true">
                                    </el-date-picker>
                                </div>
                            </el-col>
                            <el-col :span="12">
                                <div class="operations">
                                    <!-- <el-button type="success" size="small" @click="add"><i class="el-icon-plus"></i>添加</el-button> -->
                                </div>
                                <el-select v-model="staffId" placeholder="老师" clearable @change='onStaffChanged'>
                                    <el-option v-for="item in staffs" :key="item.id" :label="item.englishName" :value="item.id">
                                        {{item.englishName}} <span style="color: gray">{{item.name}}</span>
                                    </el-option>
                                </el-select>
                                <el-select v-model="courseId" placeholder="课程" clearable @change='onCourseChanged'>
                                    <el-option v-for="item in courses" :key="item.id" :label="item.name" :value="item.id">
                                    </el-option>
                                </el-select>
                                <el-button type="success" @click="onDownload()"><i class="el-icon-download"></i>下载当前页</el-button>
                            </el-col>
                        </el-row>
                        <el-table ref="multipleTable" :data="list" tooltip-effect="dark" style="width: 100%" id='dataTable'>
                            <el-table-column prop="columns.name" label="课程名称" show-overflow-tooltip>
                            </el-table-column>
                            <el-table-column prop="columns.topic" label="主题">
                            </el-table-column>
                            <el-table-column prop="columns.date" label="日期" sortable>
                            </el-table-column>
                            <el-table-column prop="columns.time" label="时间" sortable>
                            </el-table-column>
                            <el-table-column prop="columns.courseCount" label="课时">
                                <template slot-scope="scope">
                                    {{ scope.row.columns.courseCount /60 }}
                                </template>
                            </el-table-column>
                            <el-table-column prop="columns.teacher" label="老师">
                                <template slot-scope="scope">
                                    <span v-if="scope.row.columns.teacher != null && scope.row.columns.teacher != ''">{{ scope.row.columns.teacher }}</span>
                                    <span v-else-if="scope.row.columns.partTimeTeacherName != null && scope.row.columns.partTimeTeacherName != ''">{{ scope.row.columns.partTimeTeacherName }} (兼职)</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="columns.classroom" label="教室">
                            </el-table-column>
                            <el-table-column prop="columns.schoolName" label="校区">
                            </el-table-column>
                            <el-table-column prop="columns.isOnClass" label="是否已上过课">
                                <template slot-scope="scope">
                                    <span v-if="scope.row.columns.isOnClass == 1">是</span>
                                    <span v-if="scope.row.columns.isOnClass == 0">否</span>
                                </template>
                            </el-table-column>
                            <!-- <el-table-column fixed="right" label="操作" width="100">
                                <template slot-scope="scope">
                                    <el-button @click="select(scope.row.columns)" type="text" size="small">选课学生</el-button>
                                    <el-button @click="edit(scope.row.columns)" type="text" size="small">编辑</el-button>
                                    <el-button @click="del(scope.row.columns)" type="text" size="small" style="color: red;">删除</el-button>
                                </template>
                            </el-table-column> -->
                        </el-table>
                        <#include "/jh/admin/components/page.html" />
                    </template>
                </el-main>
                <el-footer></el-footer>
            </el-container>
        </el-container>
        <#include "/jh/admin/components/footer.html" />
    </div>
    <#include "/jh/admin/components/scripts.html" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/json5/0.5.1/json5.min.js"></script>
    <script src="https://cdn.bootcss.com/xlsx/0.14.0/xlsx.full.min.js"></script>
    <script src="https://cdn.bootcss.com/FileSaver.js/2014-11-29/FileSaver.min.js"></script>
    <script type="text/javascript">
    var vue = new Vue({
        el: '#app',
        data() {
            return {
                list: [],
                date: [],
                staffId: null,
                courseId: null,
                staffs: JSON.parse('${staffs!""}'),
                courses: JSON.parse('${courses!""}'),
            }
        },
        mounted: function() {
            var str = '${items!}'
            if (str != '') {
                //this.list = ${items!};
                this.list = JSON5.parse('${items!}')
            }
            var st = '${startDate!}'
            var end = '${endDate!}'
            if (st != '' && end != '') {
                this.date = [st, end]
            }
            var staffId = '${staffId!""}'
            if (staffId != '') {
                this.staffId = Number(staffId);
            }
            var courseId = '${courseId!""}'
            if (courseId != '') {
                this.courseId = Number(courseId);
            }
        },
        methods: {
            onDownload() {
                // goDownload();
                var self = this
                setTimeout(function() {
                    /* generate workbook object from table */
                    var elt = document.getElementById('dataTable');
                    var wb = XLSX.utils.table_to_book(elt)

                    // this.fixedColumn = 'right'
                    /* get binary string as output */
                    var wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: false, type: 'array' })

                    try {
                        saveAs(new Blob([wbout], { type: 'application/octet-stream' }), '上课历史_蓁奕科技.xlsx')
                    } catch (e) {
                        if (typeof console !== 'undefined') console.log(e, wbout)
                    }
                }, 1000)
                return
            },
            add() {
                window.location.href = "/jh/admin/arrange/info";
            },
            select(item) {
                window.location.href = "/jh/admin/arrange/addStudentToArrange?arrangeId=" + item.id;
            },
            edit(item) {
                window.location.href = "/jh/admin/arrange/info?arrangeId=" + item.id;
            },
            del(item) {
                var self = this;
                confirm("确认删除？", "确认", function() {
                    var param = Qs.stringify({
                        courseId: item.id
                    });
                    axios({
                            url: '/jh/admin/course/delete',
                            method: 'post',
                            data: param,
                            headers: {
                                'Content-Type': 'application/x-www-form-urlencoded'
                            }
                        })
                        .then(function(response) {
                            if (response.data.status == 200) {
                                endLoading();
                                window.location.href = "/jh/admin/course/list";
                                // msg("登录成功");
                            } else {
                                endLoading();
                                msg(response.data.msg);
                                console.log(response.data);
                            }
                        })
                        .catch(function(error) {
                            endLoading();
                            msg("删除失败");
                            console.log(error);
                        });
                })
            },
            onDateChange(val) {
                if (val == null) {
                    goPage(1)
                    return
                }
                // window.location.href = "/jh/admin/student/courseHistory?studentId=${studentId!}&startDate=" + val[0] + "&endDate=" + val[1];
                var keys = [
                    { 'key': 'startDate', "value": val[0] },
                    { 'key': 'endDate', "value": val[1] },
                ]
                goPage(1, keys)
            },
            onStaffChanged() {
                var keys = [
                    { key: 'staffId', value: this.staffId }
                ]
                goPage(1, keys)
            },
            onCourseChanged() {
                var keys = [
                    { key: 'courseId', value: this.courseId }
                ]
                goPage(1, keys)
            },
            onPageChange(val) {
                // console.log('当前页: {val}' + val);
                goPage(val)
            }
        }
    })
    </script>
    <style type="text/css">
    .title {
        font-size: 18px;
        font-weight: bold;
    }

    .datepicker {
        margin-left: 1rem;
    }

    .operations {
        text-align: right;
    }
    </style>
    <#include "/jh/admin/components/msg.html" />
</body>

</html>